package com.example.basemvvmkotlin.fragment

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.basemvvmkotlin.R
import com.example.basemvvmkotlin.databinding.ActicityRvBinding
import com.example.basemvvmkotlin.net.DataList
import com.example.basemvvmkotlin.vm.NewsListVm
import com.example.lib_base.base.adapter.LoadMoreAdapter
import com.example.lib_base.base.fragment.BaseRVFragment

class TestRvFragment:BaseRVFragment<ActicityRvBinding, NewsListVm, DataList>() {

    override fun initialize(savedInstanceState: Bundle?) {
        super.initialize(savedInstanceState)
        initRecyclerView()
        binding.btn.setOnClickListener {
            page = 1
            viewModel.getNewsListBean(page)
        }
        binding.btn2.setOnClickListener {
            onLoadMore()
        }
    }

    override fun createAdapter(): BaseQuickAdapter<DataList, BaseViewHolder> {
        return object : LoadMoreAdapter<DataList, BaseViewHolder>(R.layout.item_news){
            override fun convert(holder: BaseViewHolder, item: DataList) {
                holder.setText(R.id.title,item.title)
            }
        }
    }

    override fun createClass(): Class<*> {
        return DataList::class.java
    }

    override fun createListData(page: Int) {
        viewModel.getNewsListBean(page)
    }

    override fun createViewModel(): NewsListVm {
        return NewsListVm()
    }

    override fun getLayoutId(): Int {
        return R.layout.acticity_rv
    }
}